<?php

if (!defined('IN_ANWSION'))
{
	die;
}

class news extends AWS_CONTROLLER
{
	function get_permission_action()
	{
	
	}

	public function setup()
	{
		$this->model('admin_session')->init($this->get_permission_action());

		TPL::assign('menu_list', $this->model('admin_group')->get_menu_list($this->user_info['group_id'], 304));
	}

	public function index_action()
	{
		$this->list_action();
	}

	public function list_action()
	{
		$per_page = 20;
		
		$page_id = intval($_GET['page_id']);
		
		$question_id = intval($_GET['id']);
		
		$question_name = $_GET['name'];
		
		$page_id = ($page_id == 0) ? 1 : $page_id;
		
		$limit = ($page_id - 1) * $per_page . "," . $per_page;
		
		$news_list = $this->model('question')->get_question_news_list($question_id,$limit);

		AWS_APP::pagination()->initialize(array(
			'base_url' => get_setting('base_url') . '/?/admin/news/list/',
			'total_rows' => count($news_list),
			'per_page' => $per_page,
			'last_link' => "末页",
			'first_link' => "首页",
			'next_link' => "下一页 »",
			'prev_link' => "« 上一页",
			'anchor_class' => ' class="number"',
			'cur_tag_open' => '<a class="number current">',
			'cur_tag_close' => '</a>',
			'direct_page' => TRUE
		));
		
		$this->crumb("新闻管理 - ".$question_name	, "admin/news/list/");
	
		TPL::assign('pagination', AWS_APP::pagination()->create_links());
		
		TPL::assign('question_id', $question_id);
		
		TPL::assign('list', $news_list);
		
		TPL::output("admin/news/list");
	}
	
	/**
	 * 编辑广告
	 * @author LSH 2013-01-19
	 * @return boolean
	 */
	public function ajax_save_action()
	{
		
		$edit = $_POST['arg'];

		
		if($this->model('question')->edit_question_news($edit))
		{
			echo '1';
		}
		else
		{
			echo '0';
		}
		
		return true;
	}
	
	/**
	 * 添加广告
	 * @athor LSH 2013-01-20
	 * @return boolean
	 */
	public function ajax_add_action()
	{
		$add = $_POST['arg'];
				
		
		if ($this->model('question')->add_question_news($add))
		{
			echo 1;
		}
		else
		{
			echo 0;
		}
		
		return true;
	}
	
	public function ajax_del_action()
	{
		$id = $_POST['news_id'];
		
		if ($this->model('question')->del_question_new($id))
		{
			echo '1';
		}
		else
		{
			echo '0';
		}
	}
}